package com.cddx.logistics.controller;

import com.cddx.logistics.domain.dto.SysDictQueryDTO;
import com.cddx.logistics.domain.pojo.SysDict;
import com.cddx.logistics.domain.vo.SysDictVO;
import com.cddx.logistics.service.SysDictService;
import com.cddx.logistics.util.model.R;
import com.cddx.logistics.util.model.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "字典管理控制器")
@RequestMapping("/sysDict")
public class SysDictController {
    @Resource
    private SysDictService sysDictService;
    /**
     * 分页查询字典
     * @param sysDictQueryDTO
     * @return
     */
    @GetMapping("/queryPage")
    @ApiModelProperty("分页查询字典")
    public R   queryPage(SysDictQueryDTO sysDictQueryDTO){
        PageInfo<SysDictVO> pageInfo = sysDictService.queryPage(sysDictQueryDTO);
        return R.ok(pageInfo);
    }

    /**
     * 删除字典
     */
    @GetMapping("/delete")
    @ApiModelProperty("删除字典")
    public Result delete(Integer id){
        return sysDictService.delete(id);
    }

    /**
     * 添加字典
     */
    @PostMapping("/add")
    @ApiModelProperty("添加字典")
    public R   add(SysDict sysDict){
        return sysDictService.add(sysDict)?R.ok("添加成功"):R.error("添加失败");
    }

    /**
     * 修改字典
     */
    @PostMapping("/update")
    @ApiModelProperty("修改字典")
    public R   update(SysDict sysDict){
        return sysDictService.update(sysDict)?R.ok("修改成功"):R.error("修改失败");
    }

    /**
     * 批量删除字典
     */
    @GetMapping("/deleteBatch")
    @ApiModelProperty("批量删除字典")
    public Result deleteBatch(@RequestParam("ids") List<Integer> ids) {
        return sysDictService.deleteBatch(ids);
    }



}
